package com.itheima.app.exception;

import com.itheima.domain.vo.ErrorResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @Author 请不要叫我高司令
 * @Date 2022/3/14 22:58
 * @Version 1.0
 */

@ControllerAdvice // aop捕获controller抛出异常
public class GlobalExceptionAdvice {


    // 捕获全局非预期异常
    @ExceptionHandler(Exception.class)
    public ResponseEntity exceptionMethod(Exception ex){
        // 1.将异常信息打印到控制台
        ex.printStackTrace();
        // 2.友情提示
        return ResponseEntity.status(500).body(ErrorResult.error());
    }
}
